/*================================================================
*   Copyright (C) 2018  All rights reserved.
*   
*   Filename：udp_client.c
*   Creator ：pony
*   Create  date：2018-01-29
*   Description：
*
================================================================*/

#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <netinet/in.h>
#include <string.h>

#define SERVERPORT 6666
#define MAXBYTES 32


int main(int argc, char** argv)
{
	struct sockaddr_in servaddr;
	int sockfd;
	int len;
	char buff[MAXBYTES];

	sockfd = socket(AF_INET,SOCK_DGRAM,0);
	bzero(&servaddr,sizeof(servaddr));	
	servaddr.sin_family = AF_INET;
	inet_pton(AF_INET,"127.0.0.1",&servaddr.sin_addr);
	servaddr.sin_port = htons(SERVERPORT);

	while (fgets(buff,MAXBYTES,stdin) != NULL)
	{
		len = sendto(sockfd,buff,strlen(buff)+1,0,(struct sockaddr *)&servaddr,sizeof(servaddr));
		if(len == -1)
		{
			perror("sendto");
			continue;
		}

	}
	close(sockfd);
	return 0;
}
